/***************************************************************************
 *   Copyright (C) 2009 by maarten,,,   *
 *   maarten@maarten-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "objects/vertex.h"
#include <QString>
#include <iostream>
#include "cgpanel/floatmatrix.h"

using namespace std;

#include <math.h>

namespace object {

void Vertex::normalize()
{
  vLenght = sqrt((m_x *m_x) + (m_y * m_y) + (m_z * m_z) + (m_h * m_h));
  m_x = m_x/vLenght;
  m_y = m_y/vLenght;
  m_z = m_z/vLenght;
  m_h = m_h/vLenght;      
}

void Vertex::unNormalize()
{
    m_x = m_x*vLenght;
    m_y = m_y*vLenght;
    m_z = m_z*vLenght;
    m_h = m_h*vLenght;
}

void Vertex::transform(draw::FloatMatrix * val)
{
  Vertex * newV = val->multiplyWith(this);
  m_x= newV->x();
  m_y = newV->y();
  m_z= newV->z();
  m_h = newV->h();
  vLenght = sqrt((m_x *m_x) + (m_y * m_y) + (m_z * m_z) + (m_h * m_h));
  delete newV;
}

void Vertex::print()
{
    cout << "x:" << m_x << endl;
    cout << "y:" << m_y << endl;
    cout << "z:" << m_z << endl;
}
}
